<?php

include_once 'Expression.php';

/**
 * Represents a reference to an index of an array.
 * 
 * @package UC_PHPCodeModel
 * @author Uros Calakovic
 * @example ../Examples/ArrayIndexerExpressionExample.php 
 */

class ArrayIndexerExpression extends Expression
{
    /**
     * ArrayIndexerExpression constructor
     * 
     * @param ExpressionCollection $Indices Array indices collection
     * @param Expression $TargetObject The target array expression
     */
    
    public function __construct(
        ExpressionCollection $Indices = null, Expression $TargetObject = null)
    {
        parent::__construct();
        
        $Indices == null ? 
            $this->Indices = new ExpressionCollection() : 
            $this->Indices = $Indices;
        
        $TargetObject == null ? 
            $this->TargetObject = new Expression() : 
            $this->TargetObject = $TargetObject;
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @param mixed $value The value the field should be set to, usually a collection.
     * @see CodeObject::__set()
     */
    
    public function __set($name, $value)
    {
        parent::__set($name, $value);
        
        if($name == 'Indices')
        {
            $this->set_Indices($value);
        }
        
        if($name == 'TargetObject')
        {
            $this->set_TargetObject($value);
        }
    }
    
    /**
     * Used for making private / protected variables 
     * accessible from outside the class.
     * 
     * @param string $name Name of the field to be accessed
     * @return mixed The field that $name specified, usually a collection
     * @see CodeObject::__get()
     */
    
    public function __get($name)
    {
        $ret = parent::__get($name);
        
        if($ret != null)
        {
            return $ret;
        }
        
        if($name == 'Indices')
        {
            return $this->get_Indices();
        }
        
        if($name == 'TargetObject')
        {
            return $this->get_TargetObject();
        }
    }
    
    /**
     * The $Indices getter method
     * @return ExpressionCollection 
     */
    
    public function get_Indices()
    {
        return $this->Indices;
    }

    /**
     * The $Indices setter method.
     * @param ExpressionCollection $Indices 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     */
    
    public function set_Indices(ExpressionCollection $Indices)
    {
        $this->Indices = $Indices;
    }

    /**
     * The $TargetObject getter method
     * @return Expression
     */
    
    public function get_TargetObject()
    {
        return $this->TargetObject;
    }

    /**
     * The $TargetObject setter method
     * @param Expression $TargetObject 
     * 
     * @assert (123) throws PHPUnit_Framework_Error
     * @assert ('name') throws PHPUnit_Framework_Error
     */
    
    public function set_TargetObject(Expression $TargetObject)
    {
        $this->TargetObject = $TargetObject;
    }

    /**
     * The target array index collection
     * @var ExpressionCollection 
     */
    
    private $Indices;
    
    /**
     * The target array
     * @var Expression 
     */
    
    private $TargetObject;
}

?>
